﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Generic;
using Code;

namespace E2_WEBSITE.Code.Company
{
    public class CompanyDataAccess
    {
        protected DataProvider _provider = DataProvider.GlobalDataProvider;

        public List<CompanyInfo> GetLstCompanyInfo()
        {
            try
            {
                string strSQL = string.Format("SELECT THONG_TIN.*, NGUOI_DUNG.Email as EmailNguoiDung, NGUOI_DUNG.Ten FROM THONG_TIN, NGUOI_DUNG WHERE THONG_TIN.NguoiCapNhat = NGUOI_DUNG.id");
                DataTable table = _provider.ExecuteQueryDataTable(strSQL);

                List<CompanyInfo> lst = new List<CompanyInfo>();
                
                foreach (DataRow row in table.Rows)
                {
                    CompanyInfo companyInfo = new CompanyInfo();

                    companyInfo.BannerUrl = row["BannerUrl"].ToString();
                    companyInfo.CongTy = row["CongTy"].ToString();
                    companyInfo.DiaChi = row["DiaChi"].ToString();
                    companyInfo.Email = row["Email"].ToString();
                    companyInfo.ID = int.Parse(row["id"].ToString());
                    companyInfo.NgayCapNhat = DateTime.Parse(row["NgayCapNhat"].ToString());
                    companyInfo.SDT = row["SDT"].ToString();

                    companyInfo.NguoiCapNhat = new MemberInfo();
                    companyInfo.NguoiCapNhat.Ten = row["Ten"].ToString();
                    companyInfo.NguoiCapNhat.Email = row["EmailNguoiDung"].ToString();                                       

                    lst.Add(companyInfo);
                }

                return lst;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }
}
